package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_DaChiZi
 * Date: 2025/6/25
 * Time: 15:54
 */

public class Test {
    private static Object locker1 = new Object();
    private static Object locker2 = new Object();
    private static Object locker3 = new Object();


    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while(true) {
                synchronized (locker1) {
                    try {
                        locker1.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print('A');
                }
                synchronized (locker2) {
                    locker2.notify();
                }

            }
        });
        Thread t2 = new Thread(() -> {
            while(true) {
                synchronized (locker2) {
                    try {
                        locker2.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print('B');
                }
                synchronized (locker3) {
                    locker3.notify();
                }
            }
        });
        Thread t3 = new Thread(() -> {
            while(true) {
                synchronized (locker3) {
                    try {
                        locker3.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println('C');
                }
                synchronized (locker1) {
                    locker1.notify();
                }
            }
        });
        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(100);
        synchronized (locker1) {
            locker1.notify();
        }


//        t1.join();
//        t2.join();
//        t3.join();
    }
}
